package com.doit.doit47;

import org.apache.kafka.clients.admin.*;
import org.apache.kafka.common.KafkaFuture;
import org.apache.kafka.common.TopicPartitionInfo;

import java.util.*;
import java.util.concurrent.ExecutionException;

public class _06_kafka的topic管理 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Properties props = new Properties();
        props.setProperty(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG,MyKafkaConfig.CONSUMER_HOST_NAME);
        AdminClient adminClient = KafkaAdminClient.create(props);
        DescribeTopicsResult guangge = adminClient.describeTopics(Arrays.asList("guangge"));

        Map<String, KafkaFuture<TopicDescription>> values = guangge.values();
        Set<Map.Entry<String, KafkaFuture<TopicDescription>>> entries = values.entrySet();
        for (Map.Entry<String, KafkaFuture<TopicDescription>> entry : entries) {
            KafkaFuture<TopicDescription> value = entry.getValue();
            TopicDescription topicDescription = value.get();
            List<TopicPartitionInfo> partitions = topicDescription.partitions();
            int size = partitions.size();

        }

    }
}
